<template>
  <div class="wrap"> <!-- 挂牌 11，集采 10，竞价 12 -->
    <el-button v-if="((type=== 11 || type=== 10 || type=== 12) && order.status === 1 && userInfo.type ===1)"
     type="primary" size="mini" @click="handle(order)">确认订单</el-button>

    <!-- 委托代购 13 -->
    <el-button v-if="((type === 13) && order.status === 1)"
     type="primary" size="mini" @click="handle(order)">确认订单</el-button>

    <el-dialog title="确认订单" :visible.sync="show" width="800px" append-to-body>
      <DeliveryAddress @updateAddress="updateAddress" />
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handlePay">立即付款</el-button>
      </div>
    </el-dialog>

    <!-- 商城订单 -->
    <el-button type="primary" size="mini" @click="toPay(order)"
      v-if="((type=== 1) &&  order.status===1 && order.status !== 14 && userInfo.type ===1)">立即付款</el-button>
  </div>
</template>

<script>
import DeliveryAddress from '@/components/DeliveryAddress'
import {
   updateOrderAddress
} from '@/api/mall'

export default {
  name: 'ConfirmOrderButton',
  props: {
    userInfo: {
      type: Object,
      default: () => ({})
    },
    order: {
      type: Object,
      default: () => ({})
    },
    type: {
      type: Number,
    }
  },
  components: {
    DeliveryAddress
  },
  data() {
    return {
      show: false,
      addressId:'',
    }
  },
  computed: {},
  watch: {},
  methods: {
    handle() {
      this.show = true
    },
    updateAddress(id) {
      this.addressId = id;
    },
    handlePay() {
      if (!this.addressId) {
        this.$message.error("请选择地址！")
        return;
      }
      const param = {
        'originalId' : this.order.id,
        'addressId' : this.addressId
      }
      updateOrderAddress(param).then(response => { 
        this.toPay(this.order)
      }).catch(error => {
        console.log(error);
      })
    },
    toPay(row) {
      if (!row || !row.id) {
        return
      }
      // this.$router.push({ path: '/confirm-pay', query: { id: `/${row.id}/`, amount: row.totalAmount, orderNb: row.identifier, isPay: 1, channel: '99' } })
      this.show = false
      const { href } = this.$router.resolve({
        path: "/confirm-pay",
        query: {
          id: `/${row.id}/`, 
          amount: row.totalAmount, 
          orderNb: row.identifier, 
          isPay: 1,
          channel: '99',
          orderWhere: row.orderWhere
        }
      });
      window.open(href, '_blank');
    },
  },
  created() {
    
  },
  mounted() {
    
  },
  beforeCreate() {},
  beforeMount() {},
  beforeUpdate() {},
  updated() {},
  beforeDestroy() {},
  destroyed() {},
  activated() {},
}
</script>

<style lang='scss' scoped>
  .wrap {
    display: inline-block;
  }
</style>